<template>
  <div class="root-box">
    <!--    背景块 -->
    <waves :top="50"></waves>
    <h1
        class="color-[#000000] absolute margin-[0] top-[10%] left-[20%] text-[6vh]"
    >
      OTA 配置中心
    </h1>

    <img src="@/assets/login.png" class="fixed left-[10vw] top-[20vh] w-[40vw]">

    <div
      class="translaye-y-[50px] absolute right-[10vw] top-[25vh]"
    >
      <el-form
        ref="loginRef"
        :model="loginForm"
        label-width="auto"
        :rules="loginRules"
        class="login-form width-[15vw]"
      >
        <div class="title-box">
          <span class="title">账户登录</span>
        </div>
        <el-form-item prop="username" label="用户名:">
          <el-input
            v-model="loginForm.username"
            type="text"
            size="large"
            auto-complete="off"
            placeholder="请输入账号"
          >
            <template #prefix>
              <svg-icon icon-class="user" class="el-input__icon input-icon" />
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="password" label="密码:" style="margin-top: 3vh">
          <el-input
            v-model="loginForm.password"
            type="password"
            show-password
            size="large"
            auto-complete="off"
            placeholder="请输入密码"
            @keyup.enter="LoginApiFun"
          >
            <template #prefix>
              <svg-icon
                icon-class="password"
                class="el-input__icon input-icon"
              />
            </template>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            :loading="loading"
            size="large"
            type="primary"
            style="width: 100%; margin-top: 7vh; margin-bottom: 2vh"
            color="rgba(54, 122, 255, 1)"
            @click.prevent="LoginApiFun"
          >
            <span v-if="!loading">登 录</span>
            <span v-else>登 录 中...</span>
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup lang="ts">
import waves from "../../components/waves.vue";
import { LoginAuthApi } from "../../service/port";
import { ElMessage } from "element-plus";
import Router from "../../router/index";

import { ref } from "vue";

const loading = ref(false);
const loginRef = ref(null);

const loginForm = ref({
  username: "",
  password: "",
});
const loginRules = {
  username: [{ required: true, trigger: "blur", message: "请输入您的账号" }],
  password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
};

//登陆方法
const LoginApiFun = () => {
  console.log("调用登录", loginRef.value);
  loginRef.value.validate(async (valid: boolean) => {
    if (valid) {
      console.log("校验通过", loginRef.value);
      const res = await LoginAuthApi(
        loginForm.value.username,
        loginForm.value.password
      );
      if (res.code == 200) {
        console.log("登陆成功", res);
        //存储sessionId
        localStorage.setItem("sessionId", res.data);
        //路由跳转
        Router.replace({ path: "/" });
      } else {
        ElMessage.error(res.data);
      }
    } else {
      ElMessage.warning("登录信息未完善");
    }
  });
};
</script>

<style lang="scss" scoped>
.root-box {
  position: relative;
  height: 100%;
  //background-image: url("../assets/images/login-background.png");
  background-size: cover;
  background-color: #ffffff;
}

.login {
  color: rgba(255, 255, 255, 0.68);
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  //flex-direction: column;
  z-index: 10;
}

.title {
  margin: 0 10px 30px 10px;
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  line-height: 45px;
  display: inline-block;
  color: #000000;
}

.login-form {
  background: linear-gradient(145deg, #ffffff, #f0f0f0);
  box-shadow:
      0 10px 20px rgba(0, 0, 0, 0.1),
      0 6px 6px rgba(0, 0, 0, 0.1),
      0 0 0 1px rgba(0, 0, 0, 0.05); /* 边框效果 */
  border-radius: 8px 8px 8px 8px;
  opacity: 1;

  border-image: linear-gradient(
      136deg,
      rgba(255, 255, 255, 1),
      rgba(255, 255, 255, 0)
    )
    1 1;

  padding: 2rem 4rem 0.5rem 4rem;

  .el-input {
    height: 40px;
    input {
      height: 40px;
    }
  }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 0;
  }
}

.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-size: 12px;
  letter-spacing: 1px;
}

//:deep .el-input__wrapper {
//  background: none;
//  box-shadow: none;
//  border-radius: unset;
//  //box-shadow: rgba(255, 255, 255, 0.18) 0 10px 1px;
//  border-bottom: rgba(255, 255, 255, 0.18) solid 1px;
//}
//
//:deep .el-input__inner {
//  color: rgba(255, 255, 255, 1);
//}

:deep .el-divider__text {
  background-color: transparent;
  color: rgba(255, 255, 255, 0.68);
}

.zs- {
  color: rgba(255, 255, 255, 0.68);

  &::before {
    border-bottom: 1px rgba(255, 255, 255, 0.18) solid;
    flex: 1;
    content: "";
    margin-right: 20px;
  }

  &::after {
    border-bottom: 1px rgba(255, 255, 255, 0.18) solid;
    flex: 1;
    content: "";
    margin-left: 20px;
  }

  & div {
    transform: translateY(-50%);
  }

  align-items: center;
  display: flex;
}

.title-box {
  display: flex;
  justify-content: center;
  cursor: pointer;
  margin: 20px auto;
}
</style>
